<?php 
    session_start();
//    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "seller")){        
        
        $button = $_POST["button"];
        $categoryID = $_POST["categoryID"];
        $categoryName = $_POST["categoryName"];
        $categoryDescription = $_POST["categoryDescription"];
        
        if(strcmp($button, "Cancel")){
        $con = mysql_connect("localhost", "zhouzhao", "19831022");
        if(!$con){
            die("could not connect to DB: ".mysql_error());
        }
        
        mysql_selectdb("cloudcom", $con);
        
        $result = mysql_query("select * from categories where categoryID = $categoryID");
        
        if(!mysql_fetch_array($result)){
            mysql_query("insert into categories values
            ('$categoryID', '$categoryName', '$categoryDescription')");
//            echo "new category $categoryName is inserted";
        }else{
            mysql_query("update categories set categoryName='$categoryName', categoryDescription='$categoryDescription' where categoryID=$categoryID");
//            echo "record $categoryName is updated";
        }
        
        mysql_close($con);
        
        require 'seller.php';
        }else{
            require 'seller.php';
        }
        
        }else{
            require 'login.html';
        }
        ?>
    </body>
</html>
